/**
 * @description 交易对手基础信息
 * @author chenyan
 */

import { connect } from 'dva';
import React, { PropTypes, PureComponent } from 'react';
import ModalInst from '../../counterpartyManagement/creditLineManagement/creditSetting/Modal';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Row, Col, Card, Spin, Calendar, Badge, Empty, Tooltip, Button, Tabs, Modal, Select, message, Pagination } from 'antd';
import { PrimaryC } from '../../../comps';

class CreditSettingEditC extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      businessKey: undefined,
      detailData: {},
      visible: false,
    };
  }

  componentDidMount() {
    this.setState({
      businessKey: this.props.businessKey,
    });
    //交易对手短名下拉列表
    this.props.dispatch({
      type: 'creditSettingM/getShortName',
      payload: {},
    });
  }

  UNSAFE_componentWillReceiveProps(nextProps) {}
  //查询授信设置详情
  queryDetail = () => {
    this.props.dispatch({
      //查询详情数据
      type: 'creditSettingM/getCreditDetail',
      payload: {
        id: this.state.businessKey,
        type: 'approval',
      },
      callback: (data) => {
        this.setState({
          detailData: JSON.parse(JSON.stringify(data)) || {},
        });
      },
    });
  };
  render() {
    const { loading } = this.props;
    return (
      <div>
        <PrimaryC
          title={this.props.title}
          onClick={() => {
            this.queryDetail();
            this.setState({ visible: true });
          }}
        />
        <ModalInst
          type={'edit'}
          detailData={this.state.detailData}
          id={this.state.businessKey}
          visible={this.state.visible}
          titleModal='授信编辑'
          setVisible={(e) => {
            this.setState({ visible: e });
          }}
          getTableDataNew={() => {
            this.props.onOk();
          }}
          from='approval'
        />
      </div>
    );
  }
}

export default connect(({ creditSettingM, loading }) => ({ creditSettingM, loading }))(CreditSettingEditC);
